
package com.yuan.adapt;

import com.yuan.graduate.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

/**
 * 一般的适配器 只有一个textview
 * 
 * @author YUAN
 */
public class CommAdapt extends BaseAdapter {
    private LayoutInflater mInflater;
    private String key = null;
    private List<?> list;

    /**
     * @param context
     * @param list list<Map>
     * @param key 需要显示的kay值
     */
    public CommAdapt(Context context, List<?> list, String key)
    {
        mInflater = LayoutInflater.from(context);
        this.list = list;
        this.key = key;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if (list == null)
            return 0;
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null)
        {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.menu_settings_item,
                    null);
            holder.txt = ((TextView) convertView.findViewById(R.id.title));
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.txt.setText((String) ((Map<?, ?>) list.get(position)).get(key));
        return convertView;
    }

    class ViewHolder {
        TextView txt;
    }
}
